package com.example.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class MyAspectDemo {
    @Around("@annotation(com.example.aop.config.MyAspect)")
    public Object doAround1(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("around1 before...");
        Object o = null;
        try{
            o = joinPoint.proceed();
        }catch (Exception e) {
            log.error("e: " + e);
        }
        log.info("around1 after");
        return o;
    }

    @Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public Object doAround2(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("around2 before...");
        Object o = null;
        try{
            o = joinPoint.proceed();
        }catch (Exception e) {
            log.error("e: " + e);
        }
        log.info("around2 after");
        return o;
    }
}
